/////////////////////////////////////////////////////////////////////////////
// Original code from libhdfs3. Copyright (c) 2013 - 2014, Pivotal Inc.
// All rights reserved. Author: Zhanwei Wang
/////////////////////////////////////////////////////////////////////////////
//  Modifications by Kumo Inc.
// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//



#pragma once

#include <kmhdfs/common/hash.h>
#include <kmhdfs/common/session_config.h>

namespace Hdfs {
    namespace Internal {
        class RpcConfig {
        public:
            RpcConfig(const SessionConfig &conf) {
                connectTimeout = conf.getRpcConnectTimeout();
                maxIdleTime = conf.getRpcMaxIdleTime();
                maxRetryOnConnect = conf.getRpcMaxRetryOnConnect();
                pingTimeout = conf.getRpcPingTimeout();
                readTimeout = conf.getRpcReadTimeout();
                writeTimeout = conf.getRpcWriteTimeout();
                tcpNoDelay = conf.isRpcTcpNoDelay();
                lingerTimeout = conf.getRpcSocketLingerTimeout();
                rpcTimeout = conf.getRpcTimeout();
            }

            size_t hash_value() const;

            int getConnectTimeout() const {
                return connectTimeout;
            }

            void setConnectTimeout(int connectTimeout) {
                this->connectTimeout = connectTimeout;
            }

            int getMaxIdleTime() const {
                return maxIdleTime;
            }

            void setMaxIdleTime(int maxIdleTime) {
                this->maxIdleTime = maxIdleTime;
            }

            int getMaxRetryOnConnect() const {
                return maxRetryOnConnect;
            }

            void setMaxRetryOnConnect(int maxRetryOnConnect) {
                this->maxRetryOnConnect = maxRetryOnConnect;
            }

            int getReadTimeout() const {
                return readTimeout;
            }

            void setReadTimeout(int readTimeout) {
                this->readTimeout = readTimeout;
            }

            bool isTcpNoDelay() const {
                return tcpNoDelay;
            }

            void setTcpNoDelay(bool tcpNoDelay) {
                this->tcpNoDelay = tcpNoDelay;
            }

            int getWriteTimeout() const {
                return writeTimeout;
            }

            void setWriteTimeout(int writeTimeout) {
                this->writeTimeout = writeTimeout;
            }

            int getPingTimeout() const {
                return pingTimeout;
            }

            void setPingTimeout(int maxPingTimeout) {
                this->pingTimeout = maxPingTimeout;
            }

            int getLingerTimeout() const {
                return lingerTimeout;
            }

            void setLingerTimeout(int lingerTimeout) {
                this->lingerTimeout = lingerTimeout;
            }

            int getRpcTimeout() const {
                return rpcTimeout;
            }

            void setRpcTimeout(int rpcTimeout) {
                this->rpcTimeout = rpcTimeout;
            }

            bool operator ==(const RpcConfig &other) const {
                return this->maxIdleTime == other.maxIdleTime
                       && this->pingTimeout == other.pingTimeout
                       && this->connectTimeout == other.connectTimeout
                       && this->readTimeout == other.readTimeout
                       && this->writeTimeout == other.writeTimeout
                       && this->maxRetryOnConnect == other.maxRetryOnConnect
                       && this->tcpNoDelay == other.tcpNoDelay
                       && this->lingerTimeout == other.lingerTimeout
                       && this->rpcTimeout == other.rpcTimeout;
            }

        private:
            int maxIdleTime;
            int pingTimeout;
            int connectTimeout;
            int readTimeout;
            int writeTimeout;
            int maxRetryOnConnect;
            int lingerTimeout;
            int rpcTimeout;
            bool tcpNoDelay;
        };
    }
}

HDFS_HASH_DEFINE(::Hdfs::Internal::RpcConfig);
